{extend name="admin/b2c/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<!-- 选择商品图，弹出框的样式 -->
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<link href="__STATIC__/sku/jquery.ui.css" type="text/css" rel="stylesheet">
<link href="__STATIC__/sku/goods_create.css" type="text/css" rel="stylesheet">
<link href="__STATIC__/sku/base.css" type="text/css" rel="stylesheet">
<link href='ADMIN_CSS/drag_haul/jquery.gridly.css' rel='stylesheet' type='text/css'>
<link href='ADMIN_CSS/drag_haul/sample.css' rel='stylesheet' type='text/css'>
<link href='ADMIN_CSS/select_category_next.css' rel='stylesheet' type='text/css'>
<script src="ADMIN_JS/goods/release_good_second.js"></script>
<!-- <script src="ADMIN_JS/NewGetProperty.js"></script> -->
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/zh-cn.js"></script>
<script src="ADMIN_JS/ajax_file_upload.js" type="text/javascript"></script>
<script src="ADMIN_JS/image_common.js" type="text/javascript"></script>
<script src="ADMIN_JS/kindeditor-min.js" type="text/javascript"></script>
<!--  用  验证商品输入信息-->
<script src="ADMIN_JS/jscommon.js" type="text/javascript"></script>
<!-- 用 ，加载数据-->
<script type="text/javascript" src="__STATIC__/sku/goods_create.js"></script>
<script type="text/javascript" src="__STATIC__/sku/base.js"></script>
<script type="text/javascript" src="__STATIC__/sku/jquery-ui.js"></script>
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<!-- 我的图片 -->
<script src="ADMIN_JS/material_managedialog.js"></script>
<script src='ADMIN_JS/drag_haul/jquery.gridly.js' type='text/javascript'></script>
<script src='ADMIN_JS/drag_haul/sample.js' type='text/javascript'></script>
<script src='ADMIN_JS/goods/init_address.js'></script>
{/block}

{block name="main"}
<input type="hidden" id="goodsId" value="{$goods_id}" />
<input type="hidden" id="skuIsChange" value="0" />
<input type="hidden" id="shop_type" value="{$shop_type}" />
<input type="hidden" id="hidQRcode" value="" />
<!-- <input type="hidden" id="hidthumbnail" value="" /> -->
<div class="pro-form">
	<div class="content">
		<form class="form-horizontal">
			<input type="hidden" value="0" id="hiddenProductID">
			<div class="c-box">
				<h3>基本信息</h3>
				<div class="control-group text">
					<label class="control-label">商品类目：</label>
					<div class="controls" cid="{$goods_category_id}" cname="{$goods_category_name}" id="tbcName">{$goods_category_name}</div>
				</div>
				<div class="control-group text">
					<label class="control-label"><span class="color-red">*</span>商品分组：</label>
					<div class="controls product-category-position">
						<div class="productcategory-selected" id="productcategory-selected"></div>
						<a class="area-select" id="area-select" href="javascript:void(0)">选择</a>
						<span class="help-inline" style="display: none; color: red;">请选择商品分类</span>
						<div class="procategory" id="procategory" style="color:#666;">
							<ul class="clear">
								{foreach name="group_list" item="gp"}
								<li>
									<input class="input-checked" id="{$gp.group_id}" type="checkbox" value="{$gp.group_name}">
									<label for="{$gp.group_id}">{$gp.group_name}</label>
								</li>
								{/foreach}
							</ul>
						</div>
					</div>
				</div>
			</div>
			<div class="c-box">
				<h3>商品信息</h3>
				<div class="control-group">
					<label class="control-label" for="txtProductTitle"><span class="color-red">*</span>商品标题：</label>
					<div class="controls">
						<input class="productname" type="text" id="txtProductTitle">
						<span class="help-inline" style="display: none; color: red;">请输入商品标题，不能超过40个字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="brandSelect">商品品牌：</label>
					<div class="controls">
						<select id="brandSelect">
							<option value="0">请选择商品品牌</option>
							{foreach name="goodsbrand_list" item="brand"}
							<option value="{$brand.brand_id}">{$brand.brand_name}</option>
							{/foreach}
						</select>
						<span class="help-inline" style="display: none; color: red;">请选择商品品牌</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="provinceSelect">所在地：</label>
					<div class="controls">
						<select id="provinceSelect" class="auto-width" onchange="getProvince(this,'#citySelect',-1)">
							<option value="0">请选择省</option>
						</select>
						<select id="citySelect" class="auto-width">
							<option value="0">请选择市</option>
						</select>
						<!-- <span class="help-inline" style="display: none;color:red;">请选择商品区域</span> -->
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="txtProductSalePrice"><span class="color-red">*</span>原价：</label>
					<div class="controls">
						<input type="number" id="txtProductSalePrice" min="0" placeholder="0">
						<span class="help-inline">元</span>
						<span class="help-inline" style="display: none; color: red;">商品现价不能为空且需是数字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="txtProductMarketPrice"> <span class="color-red">*</span>市场价：</label>
					<div class="controls">
						<input type="number" id="txtProductMarketPrice" min="0" placeholder="0">
						<span class="help-inline">元</span>
						<span class="help-inline" style="display: none; color: red;">商品市场不能为空且需是数字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="txtProductCostPrice"><span class="color-red">*</span>成本价：</label>
					<div class="controls">
						<input type="number" id="txtProductCostPrice" min="0" placeholder="0">
						<span class="help-inline">元</span>
						<span class="help-inline" style="display: none; color: red;">商品成本不能为空且需是数字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="BasicSales"><span class="color-red"></span>基础销量：</label>
					<div class="controls">
						<input type="number" class="span1" id="BasicSales" value="0" min="0" placeholder="0">
						<span class="help-inline">件</span>
						<span class="help-inline" style="display: none; color: red;">基础销量需是数字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="BasicPraise"> <span class="color-red"></span>基础点击数：</label>
					<div class="controls">
						<input type="number" class="span1" id="BasicPraise" value="0" min="0" placeholder="0">
						<span class="help-inline">次</span>
						<span class="help-inline" style="display: none; color: red;">基础点击数需是数字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="BasicShare"> <span class="color-red"></span>基础分享数：</label>
					<div class="controls">
						<input type="number" class="span1" id="BasicShare" value="0" min="0" placeholder="0">
						<span class="help-inline">次</span>
						<span class="help-inline" style="display: none; color: red;">基础分享数需是数字</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="txtProductCodeA"><span class="color-red"></span>商家编码：</label>
					<div class="controls">
						<input type="text" id="txtProductCodeA">
						<span class="help-inline" style="display: none; color: red;">请输入商家编码</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span class="color-red"></span>商品规格：</label>
					<div class="controls">
						<div class="sku-group">
							<div class="js-sku-list-container"></div>
							<div class="js-sku-group-opts sku-sub-group">
								<h3 class="sku-group-title">
									<button type="button" class="js-add-sku-group btn">添加规格项目</button>
								</h3>
							</div>
						</div>
					</div>
				</div>
				<div class="control-group" name="skuTable" style="display: none;">
					<label class="control-label"><span class="color-red"></span>商品库存：</label>
					<div class="controls">
						<div class="js-goods-stock control-group" style="font-size: 14px; margin-top: 10px;">
							<div id="stock-region" class="sku-group">
								<table class="table-sku-stock"></table>
							</div>
						</div>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>总库存：</label>
					<div class="controls">
						<!--  disabled="disabled" class="span1"-->
						<input type="number" id="txtProductCount" min="0" value="0">
						<span class="help-inline">件</span>
						<span class="help-inline" style="display: none; color: red;">请输入总库存数量，必须是大于0的整数</span>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label" for="txtMinStockLaram"> <span class="color-red">*</span>库存预警：</label>
					<div class="controls">
						<input type="number" class="span1" id="txtMinStockLaram" min="0">
						<span class="help-inline">件</span>
						<span class="help-inline" style="display: none; color: red;">请输入库存预警数，必须是大于0的整数</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>商品图：</label>
					<div class="controls">
						<section class="example">
							<div class="gridly">
								<div class="brick small" js-img="1">
									<img id="file_upload_img_1" src="ADMIN_IMG/Default.png" alt="商品图片" />
									<a href="javascript:;" class="close-modal small" title="删除" style="display: none;">×</a>
								</div>
								<div class="brick small" js-img="2">
									<img id="file_upload_img_2" src="ADMIN_IMG/Default.png" alt="商品图片" />
									<a href="javascript:;" class="close-modal small" title="删除" style="display: none;">×</a>
								</div>
								<div class="brick small" js-img="3">
									<img id="file_upload_img_3" src="ADMIN_IMG/Default.png" alt="商品图片" />
									<a href="javascript:;" class="close-modal small" title="删除" style="display: none;">×</a>
								</div>
								<div class="brick small" js-img="4">
									<img id="file_upload_img_4" src="ADMIN_IMG/Default.png" alt="商品图片" />
									<a href="javascript:;" class="close-modal small" title="删除" style="display: none;">×</a>
								</div>
								<div class="brick small" js-img="5">
									<img id="file_upload_img_5" src="ADMIN_IMG/Default.png" alt="商品图片" />
									<a href="javascript:;" class="close-modal small" title="删除" style="display: none;">×</a>
								</div>
							</div>
							<span style="display: block; padding: 10px; margin-top: 30px; background: #eee;">必须为商品上传一张图片</span>
						</section>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>商品描述：</label>
					<div class="controls" id="discripContainer">
						<textarea id="tareaProductDiscrip" name="discripArea" style="height: 500px; width: 800px; display: none;"></textarea>
						<script id="editor" type="text/plain" style="width: 800px; height: 500px;"></script>
						<span class="help-inline" style="display: none; color: red;">请输入商品描述</span>
					</div>
				</div>
			</div>
			<div class="c-box">
				<h3>物流及其他</h3>
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>运费：</label>
					<div class="controls">
						<label class="radio inline normal"><input type="radio" name="fare" value="0" checked="checked"> 卖家承担运费</label>
						<label class="radio inline normal"><input type="radio" name="fare" value="1"> 买家承担运费</label>
						<span class="help-inline" style="display: none; color: red;">请选择运费类型</span>
					</div>
				</div>
				<div class="control-group" id="deliveryDiv" style="display: none">
					<label class="control-label"><span class="color-red">*</span>运费设置：</label>
					<div class="controls">
						<select id="deliverySelect">
							{foreach name="shipping_list" item="shipping"}
							<option value="{$shipping.shipping_fee_id}">{$shipping.shipping_fee_name}</option>
							{/foreach}
						</select>
						<!--  <a target="_blank" href="__MODULE__/Dispatching/Transportation?HeadCode=7000&MenuCode=7040">立即添加</a> -->
						<div id="deliveryFeeContainer" style="font-size: 14px;"></div>
						<span class="help-inline" style="display: none; color: red;">请选择运费模板</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>库存显示：</label>
					<div class="controls">
						<label class="radio inline normal"><input type="radio" name="stock" checked="checked" value="1"> 是</label>
						<label class="radio inline normal"><input type="radio" name="stock" value="0"> 否</label>
						<span class="help-inline" style="display: none; color: red;">请选择库存是否显示</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="PurchaseSum"><span class="color-red"></span>每人限购：</label>
					<div class="controls">
						<input type="number" class="input-mini" min="0" placeholder="0" id="PurchaseSum" name="PurchaseSum">
						<span class="help-inline">件</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>是否上架：</label>
					<div class="controls">
						<label class="radio inline normal"><input type="radio" name="shelves" value="1" checked="checked"> 立刻上架</label>
						<label class="radio inline normal"><input type="radio" name="shelves" value="0"> 放入仓库</label>
					</div>
				</div>
			</div>
			<div class="c-box">
				<h3>积分购买设置</h3>
				<div class="control-group">
					<label class="control-label"><span class="color-red">*</span>积分设置：</label>
					<div class="controls">
						<select id="integralSelect">
							<option value="0">非积分兑换</option>
							<option value="1">积分兑换</option>
						</select>
						<span class="help-inline" style="display: none; color: red;">请设置积分</span>
					</div>
				</div>

				<div class="control-group">
					<label class="control-label" for="integration_available_use">积分兑换：</label>
					<div class="controls">
						<input id="integration_available_use" name="integration_available_use" class="input-mini" placeholder="0" min="0" type="number" onchange="integrationChange(this);">&nbsp;积分
						<span class="help-inline" style="display: none; color: red;">请设置积分</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="integration_available_give">购买可赠送：</label>
					<div class="controls">
						<input id="integration_available_give" name="integration_available_give" class="input-mini" placeholder="0" min="0" type="number" onchange="integrationChange(this);">&nbsp;积分
					</div>
				</div>
			</div>
			<div class="btn-submit">
				<button class="btn btn-info" id="lastPage" onclick="location.href='__MODULE__/goods/selectcategory.html';">上一步</button>
				<button class="btn btn-info" id="btnSave" type="button" onClick="SubmitProductInfo(0,'ADMIN_MAIN','SHOP_MAIN')">保存</button>
				<button class="btn btn-info" id="btnSave2" type="button" onClick="SubmitProductInfo(1,'ADMIN_MAIN','SHOP_MAIN')">保存并预览</button>
			</div>
		</form>
	</div>
</div>
<!-- 选择sku时的弹出框 -->
<div class="select2-drop select2-display-none select2-with-searchbox select2-drop-active" id="select2-drop" style="top: 403px; left: 421.875px; width: 180px; display: none;">
	<div class="select2-search">
		<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" maxlength="4">
	</div>
	<ul class="select2-results"></ul>
</div>
{include file="admin/b2c/openDialog" /}
<script type="text/javascript">
	var root = '__ROOT__';
	var img_id_arr = "";//图片标识ID
	var speciFicationsFlag = 0;// 0：商品图的选择，1：规格的图片选择,2:商品详情的图片
	var speciFicationsImgCid = -1;//规格图片Id，动态控制规格图片的变化
	var speciFicationsLength = 0;// 保存图片数量
	var speciFlcationsImgSrc = new Array();//保存图片路径
	var speciFlcationsImgIdList = new Array();//图片Id
	var IsShowImg = false;// 是否添加规格图片，checkbox
	var atomIdArr = new Array();//第一个规格的图片ID
	var FirstImgId = -1;//第一个规格的ID
	var obj = null;//图片对象，用于加载图片
	var shopImageFlag = -1;//所点击的商品图片标识
	var goodsFigure = null;//商品图对象
	// 实例化编辑器，建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor');
	$('.gridly').gridly({
		base : 60, // px 
		gutter : -20, // px
		columns : 12
	});
	initProvince("#provinceSelect");
	function PopUpCallBack(idlist, srclist) {
		var idArr, srcArr;
		if (idlist.indexOf(",")) {
			idArr = idlist.split(',');
			srcArr = srclist.split(',');
		} else {
			idArr = idlist;
			srcArr = srclist;
		}
		if (speciFicationsFlag == 0) {
			$("#file_upload_img_" + shopImageFlag).attr("src", srcArr);
			$("#file_upload_img_" + shopImageFlag).attr("data-id", idArr);
			$(goodsFigure).children("a").show();
		} else if (speciFicationsFlag == 1) {
			//判断当前下标是否存在，不存在进行添加，否则进行修改
			var str = '<a href="javascript:;" class="close-modal small "title="删除">×</a> ';
			str += '<img src="' + srcArr
					+ '" cid="spec_img_'
					+ speciFicationsImgCid
					+ '" style="width:84px;height:84px;" index="'+speciFicationsImgCid+'" />';
			str += '<span>替换</span>';
			$(obj).html(str);
			//alert(speciFlcationsImgSrc[speciFicationsImgCid]);
			if (speciFlcationsImgSrc[speciFicationsImgCid] == null) {
				speciFlcationsImgSrc.push(srcArr);
				speciFlcationsImgIdList.push(idlist);
			} else {
				speciFlcationsImgSrc[speciFicationsImgCid] = srcArr;
				speciFlcationsImgIdList[speciFicationsImgCid] = idlist;
			}
		} else if (speciFicationsFlag == 2) {
			for (var i = 0; i < srcArr.length; i++) {
				var description = "<img src='"+srcArr[i]+"' />";
				ue.setContent(description, true);
			}
		}
	}
	function setGoodsFigure(goodsFigure) {
		this.goodsFigure = goodsFigure;
	}

	//设置当前图片（SKU图片，商品规格）
	function setObject(obj) {
		this.obj = obj;
	}
	//设置商品详情的图片
	function setUeditorImg() {
		speciFicationsFlag = 2;
		OpenPricureDialog("PopPicure", ADMINMAIN, 5);
	}
</script>
{/block}